﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using System;
using System.ComponentModel;

namespace LM.CB.K3Cloud.Plugin
{
    /// <summary>
    /// 工艺路线(二开)操作插件
    /// </summary>
    /// <remarks>
    /// 功能：工艺路线(二开)点审核后，同一组织同一自制产品只有一个标准工艺路线。
    /// 创建人：吴振金
    /// 创建日期：2024-02-19
    /// </remarks>
    [Description("审核更新字段-默认版本")]
    [Kingdee.BOS.Util.HotUpdate]
    public class ProcessRouteUpdate : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            base.OnPreparePropertys(e);
            e.FieldKeys.Add("FUSEORGID");//组织
            e.FieldKeys.Add("F_DEV_CPBM");//产品编码
            e.FieldKeys.Add("F_DEV_MRBB");//默认版本
        }

        public override void EndOperationTransaction(EndOperationTransactionArgs e)
        {
            base.EndOperationTransaction(e);

            foreach (DynamicObject data in e.DataEntitys)
            {
                string fid = Convert.ToString(data["id"]);
                string OrgId = Convert.ToString(data["FUSEORGID_id"]);
                string CPBM = Convert.ToString(data["F_DEV_CPBM_id"]);
                string MRBB = Convert.ToString(data["F_DEV_MRBB"]);
                if (MRBB == "True") //勾选默认版本时
                {
                    string strSql = string.Format(@"/*dialect*/update DEV_t_ProcessRoute set F_DEV_MRBB='0' 
                                                               where FUSEORGID='{0}' and F_DEV_CPBM='{1}' and fid<>{2}",
                                                               OrgId, CPBM, fid);//更新相同组织和产品编码的默认版本为未勾选
                    DBUtils.Execute(Context, strSql);
                }
            }
        }
    }
}
